home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- global proc float ikFkBlendValue(string $selectionList[])
- //
- // Description:
- // Returns the float value of the solver blend value of the
- // selected joint chains or ikHandles. If all the selected objects
- // do not have the same blend value, returns -1.
- //
- {
- float $blendValue = -1.0;
-
- int $nOtherHandles = 0;
- string $otherHandles[];
- int $nOtherJoints = 0;
- string $otherJoints[];
-
- string $xforms[] = `ls -type transform $selectionList`;
- int $nXforms = size($xforms);
- if (0 == $nXforms) {
- return $blendValue;
- }
-
- string $ikRelated[] = `ls -type joint -type ikHandle $selectionList`;
- int $nIKRelated = size($ikRelated);
- if ($nIKRelated != $nXforms) {
- string $item;
- for ($item in $xforms) {
- string $attrName;
- if (size(`ls ($item+".solverEnable")`)) {
- $attrName = ($item+".solverEnable");
- } else if (size(`ls ($item+".ikBlend")`)) {
- $attrName = ($item+".ikBlend");
- }
- if (size($attrName)) {
- string $cnx[] = `listConnections -d 0 $attrName`;
-
- if (size($cnx) > 0 &&
- !size(`ls -type joint $cnx[0]`)) {
- if (size(`ls -type ikHandle $cnx[0]`) > 0) {
- $otherHandles[$nOtherHandles++] = $cnx[0];
- } else if (size(`ls -type joint $cnx[0]`) > 0) {
- $otherJoints[$nOtherHandles++] = $cnx[0];
- }
- }
- }
- }
- }
-
- if ($nIKRelated == 0 && $nOtherHandles == 0 && $nOtherJoints == 0) {
- return $blendValue;
- }
-
- int $hasResult = false;
- int $mixed = false;
-
- string $selectedHandles[] = `ls -type "ikHandle" $ikRelated`;
- int $nHandles = size($selectedHandles);
-
- // Add the other handles that may be involved.
- //
- for ($item in $otherHandles) {
- $selectedHandles[$nHandles++] = $item;
- }
-
- string $item;
- for ($item in $selectedHandles) {
- float $currBlend = `getAttr ($item+".ikBlend")`;
-
- if (!$hasResult) {
- $blendValue = $currBlend;
- $hasResult = true;
- } else {
- if (abs($blendValue - $currBlend) > 0.001) {
- $mixed = true;
- break;
- }
- }
- }
-
- if (!$mixed) {
- // Only look at the joints if it is necessary.
- //
- string $handles[] = `ls -type ikHandle`;
- string $jointList[] = `ls -type "joint" $ikRelated`;
- int $jointIndex = size($jointList);
- for ($item in $otherJoints) {
- $jointList[$jointIndex++] = $item;
- }
-
- string $selected;
- for ($selected in $jointList) {
- string $h;
- for ($h in $handles) {
- string $joints[] = `ikHandle -q -jl $h`;
-
- int $nJoints = size($joints);
- $joints[$nJoints] = `ikHandle -q -sj $h`;
-
- string $j;
- for ($j in $joints) {
- if (size(`match $selected $j`) > 0 &&
- size(`match ($selected+"|") $j`) == 0) {
- string $attrName = ($h+".ikBlend");
- if (size(`ls ($h+".solverEnable")`)) {
- $attrName = ($h+".solverEnable");
- }
- float $currBlend = `getAttr $attrName`;
- if (!$hasResult) {
- $blendValue = $currBlend;
- $hasResult = true;
- } else {
- if (abs($blendValue - $currBlend) > 0.001) {
- $mixed = true;
- break;
- }
- }
- }
- }
-
- if ($mixed) {
- break;
- }
- }
- if ($mixed) {
- break;
- }
- }
- }
-
- if ($mixed) {
- $blendValue = -1.0;
- }
-
- return $blendValue;
- }
-